<template>
	<view class="page-box">
		<uni-section title="销售信息" type="line"></uni-section>
		<view class="form-box">
			<view v-if="house.typesOfHouseSource == 2">
				<view>房屋售价</view>
				<input v-model="house_price" type="text" placeholder="请填写房屋售价" placeholder-style="color:#bdbdbd" />
				<text>万元</text>
			</view>
			<view v-if="house.typesOfHouseSource == 3">
				<view>租金</view>
				<input v-model="house_rent" type="text" placeholder="请填写出租金" placeholder-style="color:#bdbdbd" />
				<text>元/月</text>
			</view>
			<view class="two-line-box">
				<view>分佣比例</view>
				<view class="two-line">
					<view>
						<input v-model="saler_ratio" type="text" placeholder="请填写买方佣金" placeholder-style="color:#bdbdbd" />
						<text>%</text>
					</view>
					<view>
						<input v-model="buyer_ratio" type="text" placeholder="请填写卖方佣金" placeholder-style="color:#bdbdbd" />
						<text>%</text>
					</view>
				</view>
			</view>
		</view>
		<view class="big-btn" @click="fnSubmit">发布房源</view>
	</view>
</template>

<script>
import uniSection from '@/components/uni-section/uni-section.vue';
import store from '@/store/store.vue'
export default {
	components: {
		uniSection
	},
	onLoad(option) {
		this.house = JSON.parse(decodeURIComponent(option.param))			
	},
	data() {
		return {
			house:{},
			house_price: '',
			house_rent:'',
			saler_ratio: '',				
			buyer_ratio: ''		
		}
	},
	methods: {
		fnSubmit() {
			this.house.commissionShareRatio = this.saler_ratio + ';' + this.buyer_ratio
			this.house.housePrice = this.house_price		
			this.house.house_rent = this.house_rent	
			this.house.commission_share_ratio = this.saler_ratio + ';' + this.buyer_ratio
			let _this = this		
			let url = ''
			if(this.house.typesOfHouseSource == 2){
				 url = store.url + '/house/release_second_house'
			}else if(this.house.typesOfHouseSource == 3){
				 url = store.url + '/house/release_rent_house'
			}
			if(url == ''){
				uni.showModal({
				    title: '提示',
				    content: '出现错误，请重新发布房源',
					success: function (res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/house/index'
							})
						} else if (res.cancel) {
						}
					}
				});	
				return
			}
			uni.request({
			    url: url,
				method: 'POST',
			    data: JSON.stringify(_this.house),
			    header: {
					"content-type": "application/json;charset=utf-8"						
			    },
			    success: (res) => {		
					console.log(res)
					if(res.data.status == 'success'){
							//1新房 2二手房 3租房
							let _url = '/pages/house/state?param=' + encodeURIComponent(JSON.stringify(3))
							if(getApp().globalData.inviter_id == 0){
								_url = '/pages/house/state?param=' + encodeURIComponent(JSON.stringify(1))
							}
							uni.navigateTo({
								url: _url
							})							
					}else{
						uni.showModal({
						    title: '提示',
						    content: '提交失败: ' + res.data.message
						});									
					}										        
			    },
				fail: (res)=>{
					uni.showModal({
					    title: '提示',
					    content: '访问服务器失败: ' + res.data.message
					});						
				}
			});				
		}
	}
};
</script>

<style lang="scss" scoped>
.page-box {
	padding-bottom: 88rpx;
	box-sizing: border-box;

	/deep/ .uni-section {
		margin-top: 0;
		background: #fff;
	}

	/deep/ .line {
		background-color: #f13b32;
	}
}

.form-box {
	margin-bottom: 20rpx;
	padding-left: 40rpx;
	box-sizing: border-box;
	background: #fff;

	> view {
		display: flex;
		border-bottom: 1px solid #e5e5e5;
		box-sizing: border-box;
		align-items: center;
		font-size: 24rpx;

		&:last-of-type {
			border-bottom: none;
		}
		
		&.two-line-box {
			align-items: flex-start;
		}

		> view {
			width: 140rpx;
			line-height: 80rpx;
			font-size: 24rpx;

			&.two-line {
				flex: 1;
				
				view {
					display: flex;
					align-items: center;
					border-bottom: 1px solid #e5e5e5;
					
					&:last-of-type {
						border-bottom: none;
					}
					
					input {
						flex: 1;
					}
				}

			}
		}

		input,
		.uni-input {
			padding: 20rpx 40rpx 20rpx 0;
			box-sizing: border-box;
			flex: 1;
			height: 80rpx;
			line-height: 40rpx;
		}

		text,
		uni-icons {
			padding: 0 20rpx;
			box-sizing: border-box;
		}

		picker {
			flex: 1;
			
			view {
				font-size: 24rpx;
			}
		}
	}
}

.big-btn {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	line-height: 88rpx;
	text-align: center;
	color: #fff;
	background: #f13b32;
}
</style>
